<?php

class Module_Ajax_Action{
    private $name = "";
    private $action = "";
    private $module = "";
    private $methode = "";
    private $success_funct = "";
    
    public function __construct($name = "", $module = "", $action = "", $success_funct = "", $method = "POST") {
        $this->name = $name;
        $this->action = $action;
        $this->module = $module;
        $this->methode = $method;
        $this->success_funct = $success_funct;
    }
    
    public function setName($name = ""){
        $this->name = $name;
    }
    
    public function setAction($action = ""){
        $this->action = $action;
    }
    
    public function setModule($module = ""){
        $this->module = $module;
    }
    
    public function setMethode($methode = "POST"){
        $this->methode = $method;
    }
    
    public function setSuccessFunction($success_funct = ""){
        $this->success_funct = $success_funct;
    }
    
    public function generate(){
        $head = "function " . $this->name . '(){';
        $ajax = "$.ajax({";
        $url = MODULE_REPOSITORY . '/' . $this->module->getName() . '/actions/' . $this->action;
        $foot = "});}";
        
        return $head.$ajax.
                "url:'".$url.".php',".
                "success:function(data){".
                $this->success_funct.'(data);}'.
                $foot;
    }
}

?>
